#include "FuzzyController_v1.2.hpp"


void FuzzyController()
{
	//cout.setf(ios::fixed);
	//cout.precision(2); // only display 2 decimal places

	// create and load the model
	int model = ffll_new_model();


	//int ret_val = (int)ffll_load_fcl_file(model, "..\\aiwisdom.fcl");
	int ret_val = (int)ffll_load_fcl_file(model, "fuzzycontroller.fcl");
	//int ret_val = (int)ffll_load_fcl_file(model, "aiwisdom.fcl");

	if (ret_val < 0)
	{
		cout << "Error Opening fuzzycontroller.fcl";
		getchar();
		// make sure the "working directory" in "Project | Settings..."
		// is set to the executable's directory if running from the MSVC IDE
		return 0;
	}

	// create a child for the model...
	int child = ffll_new_child(model);

	//while (1)
	//{
		cout << "SELECT AN OPTION:\n\tS - set values\n\tQ - quit";
		cout << endl;
		cin >> option;

		if (option == 'Q' || option == 'q')
			break;

		if (option == 'S' || option == 's')
		{
			cout << "Target: " ;
			cin >> target_pos;
			cout << "Obstacles: "  ;
			cin >> obstacles_pos;

			// set input variables...

			ffll_set_value(model, child, TARGET, target_pos);
			ffll_set_value(model, child, OBSTACLES, obstacles_pos);

			// get and display the output value
			int output = (int)ffll_get_output_value(model, child);  // what's output? if having 2 values?

			cout << "output: ";

			cout << output;

			switch(output)  // how to work if there are 2 values??
			{
			case (1):
				cout << "Run Away!";
				break;

			case (2):
				cout << "Fight Defensively";
				break;

			case (3):

				cout << "All Out Attack!";
				break;

			} // end switch

			cout << endl;
		} // end if option = 's'

//	} // end while(1)
}